home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / ellipse.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  10KB  |  429 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "alloc.h"
  13. #include "func.h"
  14. #include "object.h"
  15. #include "paintop.h"
  16.  
  17. extern int        cur_line_style, line_thickness;
  18. extern float        cur_styleval;
  19. extern float        cur_angle;
  20. extern int        cur_color;
  21. extern int        fix_x, fix_y, cur_x, cur_y;
  22.  
  23. extern            (*canvas_kbd_proc)();
  24. extern            (*canvas_locmove_proc)();
  25. extern            (*canvas_leftbut_proc)();
  26. extern            (*canvas_middlebut_proc)();
  27. extern            (*canvas_rightbut_proc)();
  28. extern            null_proc();
  29. extern            set_popupmenu();
  30.  
  31. extern F_compound    objects;
  32.  
  33. /*************************  local procedures  ********************/
  34.  
  35.             init_ellipsebyradius_drawing();
  36.             init_ellipsebydiameter_drawing();
  37.             init_circlebyradius_drawing();
  38.             init_circlebydiameter_drawing();
  39.             move_ebrbox(), move_ebdbox();
  40.             move_cbrbox(), move_cbdbox();
  41. int            create_ellipsebydia();
  42. int            create_ellipsebyrad();
  43. int            create_circlebyrad();
  44. int            create_circlebydia();
  45.  
  46. #define        round(z)    (int)((z)+.5)
  47.  
  48. center_marker(x, y)
  49. int    x, y;
  50. {
  51.     pw_vector(canvas_pixwin, x, y-2, x, y+2, INV_PAINT, 1);
  52.     pw_vector(canvas_pixwin, x-2, y, x+2, y, INV_PAINT, 1);
  53.     }
  54.  
  55. ellipsebyradius_drawing_selected()
  56. {
  57.     canvas_kbd_proc = null_proc;
  58.     canvas_locmove_proc = null_proc;
  59.     canvas_leftbut_proc = init_ellipsebyradius_drawing;
  60.     canvas_middlebut_proc = null_proc;
  61.     canvas_rightbut_proc = set_popupmenu;
  62.     set_cursor(&arrow_cursor);
  63.     reset_action_on();
  64.     }
  65.  
  66. init_ellipsebyradius_drawing(x, y)
  67. int    x, y;
  68. {
  69.     cur_x = fix_x = x; 
  70.     cur_y = fix_y = y;
  71.     center_marker(fix_x, fix_y);
  72.     canvas_locmove_proc = move_ebrbox;
  73.     canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
  74.     canvas_middlebut_proc = create_ellipsebyrad;
  75.     set_temp_cursor(&null_cursor);
  76.     ellipsebyrad_box(INV_PAINT);
  77.     set_action_on();
  78.     }
  79.  
  80. move_ebrbox(x, y)
  81. int    x, y;
  82. {
  83.     ellipsebyrad_box(INV_PAINT);
  84.     cur_x = x;
  85.     cur_y = y;
  86.     ellipsebyrad_box(INV_PAINT);
  87.     }
  88.  
  89. ellipsebyrad_box(op)
  90. int    op;
  91. {
  92.     register int    x1, y1, x2, y2;
  93.     int        rx, ry;
  94.  
  95.     rx = cur_x - fix_x;
  96.     ry = cur_y - fix_y;
  97.     x1 = fix_x + rx;
  98.     x2 = fix_x - rx;
  99.     y1 = fix_y + ry;
  100.     y2 = fix_y - ry;
  101.     draw_rectbox(x1, y1, x2, y2, op);
  102.     }
  103.  
  104. create_ellipsebyrad(x, y)
  105. int    x, y;
  106. {
  107.     F_ellipse    *ellipse;
  108.  
  109.     ellipsebyrad_box(INV_PAINT);
  110.     center_marker(fix_x, fix_y);
  111.     if (NULL == (Ellipse_malloc(ellipse))) {
  112.         blink_msg();
  113.         put_msg(Err_mem);
  114.         return;
  115.         }
  116.     ellipse->type = T_ELLIPSE_BY_RAD;
  117.     ellipse->style = cur_line_style;
  118.     ellipse->thickness = line_thickness;
  119.     ellipse->style_val = cur_styleval;
  120.     ellipse->angle = cur_angle;
  121.     ellipse->color = cur_color;
  122.     ellipse->depth = 0;
  123.     ellipse->pen = NULL;
  124.     ellipse->area_fill = NULL;
  125.     ellipse->direction = 1;
  126.     ellipse->center.x = fix_x;
  127.     ellipse->center.y = fix_y;
  128.     ellipse->radiuses.x = abs(x - fix_x) +1;
  129.     ellipse->radiuses.y = abs(y - fix_y) +1;
  130.     ellipse->start.x = fix_x;
  131.     ellipse->start.y = fix_y;
  132.     ellipse->end.x = x;
  133.     ellipse->end.y = y;
  134.     ellipse->next = NULL;
  135.     pw_batch_on(canvas_pixwin);
  136.     draw_ellipse(ellipse, DRAW);
  137.     pw_batch_off(canvas_pixwin);
  138.     clean_up();
  139.     set_action_object(F_CREATE, O_ELLIPSE);
  140.     insert_ellipse(&objects.ellipses, ellipse);
  141.     set_latestellipse(ellipse);
  142.     set_modifiedflag();
  143.     ellipsebyradius_drawing_selected();
  144.     }
  145.  
  146. ellipsebydiameter_drawing_selected()
  147. {
  148.     canvas_kbd_proc = null_proc;
  149.     canvas_locmove_proc = null_proc;
  150.     canvas_leftbut_proc = init_ellipsebydiameter_drawing;
  151.     canvas_middlebut_proc = null_proc;
  152.     canvas_rightbut_proc = set_popupmenu;
  153.     set_cursor(&arrow_cursor);
  154.     reset_action_on();
  155.     }
  156.  
  157. init_ellipsebydiameter_drawing(x, y)
  158. int    x, y;
  159. {
  160.     cur_x = fix_x = x; 
  161.     cur_y = fix_y = y;
  162.     center_marker(fix_x, fix_y);
  163.     canvas_locmove_proc = move_ebdbox;
  164.     canvas_leftbut_proc = null_proc;
  165.     canvas_middlebut_proc = create_ellipsebydia;
  166.     set_temp_cursor(&null_cursor);
  167.     ellipsebydia_box(INV_PAINT);
  168.     set_action_on();
  169.     }
  170.  
  171. move_ebdbox(x, y)
  172. int    x, y;
  173. {
  174.     ellipsebydia_box(INV_PAINT);
  175.     cur_x = x;
  176.     cur_y = y;
  177.     ellipsebydia_box(INV_PAINT);
  178.     }
  179.  
  180. ellipsebydia_box(op)
  181. int    op;
  182. {
  183.     draw_rectbox(fix_x, fix_y, cur_x, cur_y, op);
  184.     }
  185.  
  186. create_ellipsebydia(x, y)
  187. int    x, y;
  188. {
  189.     F_ellipse    *ellipse;
  190.  
  191.     ellipsebydia_box(INV_PAINT);
  192.     center_marker(fix_x, fix_y);
  193.     if (NULL == (Ellipse_malloc(ellipse))) {
  194.         blink_msg();
  195.         put_msg(Err_mem);
  196.         return;
  197.         }
  198.     ellipse->type = T_ELLIPSE_BY_DIA;
  199.     ellipse->style = cur_line_style;
  200.     ellipse->thickness = line_thickness;
  201.     ellipse->style_val = cur_styleval;
  202.     ellipse->angle = cur_angle;
  203.     ellipse->color = cur_color;
  204.     ellipse->depth = 0;
  205.     ellipse->pen = NULL;
  206.     ellipse->area_fill = NULL;
  207.     ellipse->direction = 1;
  208.     ellipse->center.x = (fix_x + x) / 2;
  209.     ellipse->center.y = (fix_y + y) / 2;
  210.     ellipse->radiuses.x = abs(ellipse->center.x - fix_x);
  211.     ellipse->radiuses.y = abs(ellipse->center.y - fix_y);
  212.     ellipse->start.x = fix_x;
  213.     ellipse->start.y = fix_y;
  214.     ellipse->end.x = x;
  215.     ellipse->end.y = y;
  216.     ellipse->next = NULL;
  217.     pw_batch_on(canvas_pixwin);
  218.     draw_ellipse(ellipse, DRAW);
  219.     pw_batch_off(canvas_pixwin);
  220.     clean_up();
  221.     set_action_object(F_CREATE, O_ELLIPSE);
  222.     insert_ellipse(&objects.ellipses, ellipse);
  223.     set_latestellipse(ellipse);
  224.     set_modifiedflag();
  225.     ellipsebydiameter_drawing_selected();
  226.     }
  227.  
  228. /***************************  circle  section  ************************/
  229.  
  230. circlebyradius_drawing_selected()
  231. {
  232.     canvas_kbd_proc = null_proc;
  233.     canvas_locmove_proc = null_proc;
  234.     canvas_leftbut_proc = init_circlebyradius_drawing;
  235.     canvas_middlebut_proc = null_proc;
  236.     canvas_rightbut_proc = set_popupmenu;
  237.     set_cursor(&arrow_cursor);
  238.     reset_action_on();
  239.     }
  240.  
  241. init_circlebyradius_drawing(x, y)
  242. int    x, y;
  243. {
  244.     cur_x = fix_x = x; 
  245.     cur_y = fix_y = y;
  246.     center_marker(fix_x, fix_y);
  247.     canvas_locmove_proc = move_cbrbox;
  248.     canvas_leftbut_proc = null_proc;
  249.     canvas_middlebut_proc = create_circlebyrad;
  250.     set_temp_cursor(&null_cursor);
  251.     circlebyrad_box(INV_PAINT);
  252.     set_action_on();
  253.     }
  254.  
  255. move_cbrbox(x, y)
  256. int    x, y;
  257. {
  258.     circlebyrad_box(INV_PAINT);
  259.     cur_x = x;
  260.     cur_y = y;
  261.     circlebyrad_box(INV_PAINT);
  262.     }
  263.  
  264. circlebyrad_box(op)
  265. int    op;
  266. {
  267.     register int    x1, y1, x2, y2;
  268.     int        radius, rx, ry;
  269.  
  270.     rx = cur_x - fix_x;
  271.     ry = cur_y - fix_y;
  272.     radius = round(sqrt((double) (rx*rx + ry*ry)));
  273.     x1 = fix_x + radius;
  274.     x2 = fix_x - radius;
  275.     y1 = fix_y + radius;
  276.     y2 = fix_y - radius;
  277.     draw_rectbox(x1, y1, x2, y2, op);
  278.     pw_vector(canvas_pixwin, fix_x, fix_y, cur_x, cur_y, op, 1);
  279.     }
  280.  
  281. create_circlebyrad(x, y)
  282. int    x, y;
  283. {
  284.     F_ellipse    *c;
  285.     int        rx, ry;
  286.  
  287.     circlebyrad_box(INV_PAINT);
  288.     center_marker(fix_x, fix_y);
  289.     if (NULL == (Ellipse_malloc(c))) {
  290.         blink_msg();
  291.         put_msg(Err_mem);
  292.         return;
  293.         }
  294.     c->type = T_CIRCLE_BY_RAD;
  295.     c->style = cur_line_style;
  296.     c->thickness = line_thickness;
  297.     c->style_val = cur_styleval;
  298.     c->angle = 0.0;
  299.     c->color = cur_color;
  300.     c->depth = 0;
  301.     c->pen = NULL;
  302.     c->area_fill = NULL;
  303.     c->direction = 1;
  304.     c->center.x = fix_x;
  305.     c->center.y = fix_y;
  306.     rx = fix_x - x;  ry = fix_y - y;
  307.     c->radiuses.x = c->radiuses.y = round(sqrt((double)(rx*rx + ry*ry)));
  308.     c->start.x = fix_x;
  309.     c->start.y = fix_y;
  310.     c->end.x = x;
  311.     c->end.y = y;
  312.     c->next = NULL;
  313.     pw_batch_on(canvas_pixwin);
  314.     draw_ellipse(c, DRAW);
  315.     pw_batch_off(canvas_pixwin);
  316.     clean_up();
  317.     set_action_object(F_CREATE, O_ELLIPSE);
  318.     insert_ellipse(&objects.ellipses, c);
  319.     set_latestellipse(c);
  320.     set_modifiedflag();
  321.     circlebyradius_drawing_selected();
  322.     }
  323.  
  324. circlebydiameter_drawing_selected()
  325. {
  326.     canvas_kbd_proc = null_proc;
  327.     canvas_locmove_proc = null_proc;
  328.     canvas_leftbut_proc = init_circlebydiameter_drawing;
  329.     canvas_middlebut_proc = null_proc;
  330.     canvas_rightbut_proc = set_popupmenu;
  331.     set_cursor(&arrow_cursor);
  332.     reset_action_on();
  333.     }
  334.  
  335. init_circlebydiameter_drawing(x, y)
  336. int    x, y;
  337. {
  338.     cur_x = fix_x = x; 
  339.     cur_y = fix_y = y;
  340.     center_marker(fix_x, fix_y);
  341.     canvas_locmove_proc = move_cbdbox;
  342.     canvas_leftbut_proc = null_proc;
  343.     canvas_middlebut_proc = create_circlebydia;
  344.     set_temp_cursor(&null_cursor);
  345.     circlebydia_box(INV_PAINT);
  346.     set_action_on();
  347.     }
  348.  
  349. move_cbdbox(x, y)
  350. int    x, y;
  351. {
  352.     circlebydia_box(INV_PAINT);
  353.     cur_x = x;
  354.     cur_y = y;
  355.     circlebydia_box(INV_PAINT);
  356.     }
  357.  
  358. circlebydia_box(op)
  359. int    op;
  360. {
  361.     register int    x1, y1, x2, y2;
  362.     int        radius, rx, ry;
  363.  
  364.     rx = (cur_x - fix_x) / 2;
  365.     ry = (cur_y - fix_y) / 2;
  366.     radius = round(sqrt((double) (rx*rx + ry*ry)));
  367.     x1 = fix_x + rx + radius;
  368.     x2 = fix_x + rx - radius;
  369.     y1 = fix_y + ry + radius;
  370.     y2 = fix_y + ry - radius;
  371.     draw_rectbox(x1, y1, x2, y2, op);
  372.     pw_vector(canvas_pixwin, fix_x, fix_y, cur_x, cur_y, op, 1);
  373.     }
  374.  
  375. create_circlebydia(x, y)
  376. int    x, y;
  377. {
  378.     F_ellipse    *c;
  379.     int        rx, ry;
  380.  
  381.     circlebydia_box(INV_PAINT);
  382.     center_marker(fix_x, fix_y);
  383.     if (NULL == (Ellipse_malloc(c))) {
  384.         blink_msg();
  385.         put_msg(Err_mem);
  386.         return;
  387.         }
  388.     c->type = T_CIRCLE_BY_DIA;
  389.     c->style = cur_line_style;
  390.     c->thickness = line_thickness;
  391.     c->style_val = cur_styleval;
  392.     c->angle = 0.0;
  393.     c->color = cur_color;
  394.     c->depth = 0;
  395.     c->pen = NULL;
  396.     c->area_fill = NULL;
  397.     c->direction = 1;
  398.     c->center.x = (fix_x + x) / 2 + .5;
  399.     c->center.y = (fix_y + y) / 2 + .5;
  400.     rx = x - c->center.x;  ry = y - c->center.y;
  401.     c->radiuses.x = c->radiuses.y = round(sqrt((double)(rx*rx + ry*ry)));
  402.     c->start.x = fix_x;
  403.     c->start.y = fix_y;
  404.     c->end.x = x;
  405.     c->end.y = y;
  406.     c->next = NULL;
  407.     pw_batch_on(canvas_pixwin);
  408.     draw_ellipse(c, DRAW);
  409.     pw_batch_off(canvas_pixwin);
  410.     clean_up();
  411.     set_action_object(F_CREATE, O_ELLIPSE);
  412.     insert_ellipse(&objects.ellipses, c);
  413.     set_latestellipse(c);
  414.     set_modifiedflag();
  415.     circlebydiameter_drawing_selected();
  416.     }
  417.  
  418. draw_ellipse(e, op)
  419. F_ellipse    *e;
  420. int        op;
  421. {
  422.     int    a, b;
  423.  
  424.     a = e->radiuses.x;
  425.     b = e->radiuses.y;
  426.     curve(a, 0, a, 0, e->direction, (b*b), (a*a), e->center.x, 
  427.         e->center.y, op);
  428.     }
  429.